﻿using Microsoft.AspNetCore.Mvc;
using Mojito.Model;
using Mojito.Services;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Mojito.Controllers
{
    /// <summary>
    ///  分享
    /// </summary>
    [Route("api/share")]
    public class DirectoriesShareController : ControllerBase
    {
        public DirectoriesShareService _DirectoriesShareService { get; set; }

        /// <summary>
        ///  根据工作区Id获取已经分享的用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get(string workspaceId)
        {
            var list = (await _DirectoriesShareService
                .GetUserList(workspaceId))
                .Select(d => new 
                {
                    d.Id,
                    d.Username
                });
            return Success(data: list);
        }

        /// <summary>
        ///  保存分享设置
        /// </summary>
        /// <param name="dirId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Post([FromBody] ShareSaveInput input)
        {
            await _DirectoriesShareService.Save(input);
            return Success("保存成功");
        }
    }
}
